package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 32338
 * @date 2024-04-29 18:49:44
 * @description 订单管理
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api("订单接口管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * @description
     ***:订单搜索
     **/
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索：{}",ordersPageQueryDTO);

        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * @description
     ***:统计各个状态下的订单数量
     **/
    @GetMapping("/statistics")
    @ApiOperation("统计各个状态下的订单数量")
    public Result<OrderStatisticsVO> statistics(){
        log.info("统计各个状态下的订单数量");

        OrderStatisticsVO orderStatisticsVO = orderService.statistics();

        return Result.success(orderStatisticsVO);
    }

    /**
     * @description
     ***:查询订单详情
     **/
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> detials(@PathVariable Long id){
        log.info("查询订单详情");

        OrderVO orderVO = orderService.details(id);

        return Result.success(orderVO);
    }

    /**
     * @description
     ***:商家接单
     **/
    @PutMapping("/confirm")
    @ApiOperation("商家接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("商家接单:{}",ordersConfirmDTO);

        orderService.confirm(ordersConfirmDTO);

        return Result.success();
    }

    /**
     * @description
     ***:商家拒单
     **/
    @PutMapping("/rejection")
    @ApiOperation("商家拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception{
        log.info("商家拒单");

        orderService.rejection(ordersRejectionDTO);

        return Result.success();
    }

    /**
     * @description
     ***:商家取消订单
     **/
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception{
        log.info("商家取消订单");

        orderService.cancel(ordersCancelDTO);

        return Result.success();
    }

    /**
     * @description
     ***:派送订单
     **/
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) {
        log.info("派送订单: {}",id);

        orderService.delivery(id);

        return Result.success();
    }

    /**
     * @description
     ***:完成订单
     **/
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        log.info("完成订单: {}",id);

        orderService.complete(id);

        return Result.success();
    }
}
